package C6_5_BuilderComposite.after;

import java.util.List;

/**
 * @author xufy
 * @version 1.0
 **/
public class CatalogWriter {
    public String catalogXmlFor(Activity activity) {
        TagBuilder builder = new TagBuilder("activity");
        builder.addChild("flavors");
        for (int i = 0; i < activity.getFlavorCount(); i++) {
            builder.addToParent("flavors", "flavor");
            Flavor flavor = activity.getFlavor(i);
            int requirementsCount = flavor.getRequirements().length;
            if (requirementsCount > 0) {
                builder.addChild("requirements");
                for (int j = 0; j < requirementsCount; j++) {
                    Requirement requirement = flavor.getRequirements()[j];
                    builder.addToParent("requirements", "requirement");
                }
            }
        }
        return builder.toXml();
    }
}

class Activity {
    private int flavorCount;
    List<Flavor> flavors;

    public int getFlavorCount() {
        return flavorCount;
    }

    public void setFlavorCount(int flavorCount) {
        this.flavorCount = flavorCount;
    }

    public Flavor getFlavor(int i) {
        return flavors.get(i);
    }

    public void setFlavors(List<Flavor> flavors) {
        this.flavors = flavors;
    }
}

class Flavor {

    Requirement[] requirements;


    public Requirement[] getRequirements() {
        return requirements;
    }

    public void setRequirements(Requirement[] requirements) {
        this.requirements = requirements;
    }

}

class Requirement {

}